Skip to content

fix shuffle bias in bogoSort#1886

Open
zamadye wants to merge 1 commit intoTheAlgorithms:masterfrom
zamadye:master
Open

fix shuffle bias in bogoSort#1886
zamadye wants to merge 1 commit intoTheAlgorithms:masterfrom
zamadye:master

Conversation

@zamadye
Copy link

@zamadye zamadye commented Mar 11, 2026

hey, noticed the shuffle function was using the wrong range for the random index. it was using [0, i) instead of [0, i] which makes the shuffle biased.

changed it to use (i + 1) so it includes position i in the swap. this is the correct fisher-yates implementation.

let me know if anything needs changing!

fixes #1867

@zamadye zamadye requested a review from appgurueu as a code owner March 11, 2026 08:37
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.91%. Comparing base (5c39e87) to head (3e0b705).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1886   +/-   ##
=======================================
  Coverage   85.91%   85.91%           
=======================================
  Files         379      379           
  Lines       19778    19778           
  Branches     3016     3015    -1     
=======================================
  Hits        16993    16993           
  Misses       2785     2785           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Biased shuffle implementation in bogoSort (incorrect Fisher–Yates range)

2 participants